//
//  CSprite.h
//  NinjaTurtle
//
//  Created by Nguyen Tri Chung on 1/6/15.
//
//

#ifndef __NinjaTurtle__CSprite__
#define __NinjaTurtle__CSprite__

#include <stdio.h>
#include "cocos2d.h"
#include "../global/global.h"
#include "../util/util.h"

USING_NS_CC;

class CSprite : public Sprite {
    CC_SYNTHESIZE(string, spriteType, SpriteType); // how identify each sprite
    CC_SYNTHESIZE(Point, oOVector, OOVector);
    CC_SYNTHESIZE_READONLY(string, lastActionName, LastActionName);
private:
    Action* runningAction;
    Map<string, Action*>* retainedActions; // contains retained action along to csprite
public:
    CSprite(string spriteType = "empty");
    virtual ~CSprite();
    
    bool init() override;
    bool initWithFile(const string& filename) override;
    bool initWithSpriteFrameName(const string& spriteFrameName) override;
    void initWithIdentifier(const string& identifier);
    
    Action* createFrameCaheAction(const string& pattern, int count, float duration, bool loop);
    void retainAction(Action* actionValue, const string& actionKey);
    
    void resetAction(const string& pattern, bool loop, Action* newAction);
    void playLastAction(bool loop);
    Action* getAction(const string& pattern, bool loop);
    Action* getActionExactly(const string& key);
    void bind(const string& pattern, float duration = -1);
    void play(const string& action);
    void playLoop(const string& action);
};

#endif /* defined(__NinjaTurtle__CSprite__) */
